package com.woniuxy.automotivemanagementsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.automotivemanagementsystem.entity.Menu;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MenuMapper extends BaseMapper<Menu> {


    @Select("SELECT * FROM USER u JOIN user_role ur ON u.`uid` = ur.`uid` JOIN role_menu rm ON ur.`rid` = rm.`rid` JOIN menu m ON m.`mid` = rm.`mid` WHERE u.uid = #{uid}")
    List<Menu> queryMenuByUid(@Param("uid") Integer uid);

    /*
     * 根据角色Id查询菜单
     * */
    @Select(("select * from role_menu rm join menu m on rm.mid = m.mid where rm.rid = #{rid}"))
    List<Menu> queryMenuByRid(@Param("rid") Integer rid);
    /*
    * 根据角色Id删除角色对应的菜单
    * */
    @Delete("delete from role_menu where rid = #{rid}")
    void removeByRid(Integer rid);
    /*
    * 根据角色Id和菜单Id添加角色对应的菜单
    * */
    @Insert("insert into role_menu(rid,mid) values(#{rid},#{mid})")
    void add(@Param("rid") Integer rid,@Param("mid") Integer mid);
    /*
    * 根据菜单Id查询子菜单
    * */
    @Select("select * from menu where pid = #{mid}")
    List<Menu> selectChildrenMenusByMid(Integer mid);
}


